package com.wsb.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wsb.entry.SmbmsProvider;
import com.wsb.entry.SmbmsRole;
import com.wsb.entry.SmbmsUser;
import com.wsb.service.SmbmsProviderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class SmbmsProviderController {
    @Autowired
    SmbmsProviderService smbmsProviderService;

    @RequestMapping("jsp/provider.do")
    public  String provider(HttpServletRequest req, HttpServletResponse resp){
        String pageIndex=req.getParameter("pageIndex");
        String queryname=req.getParameter("queryname");
        String queryUserRole=req.getParameter("queryUserRole");

        Page page=new Page();
        if(pageIndex==null ||pageIndex==""){
            page.setCurrent(1);
        }else{
            page.setCurrent(Long.valueOf(pageIndex));
        }
        page.setSize(5);
        SmbmsProvider smbmsProvider=new SmbmsProvider();
       // if(queryname!=null&&queryname!=""){
        //    smbmsProvider.setUserName(queryname);
        //}
        //if(queryUserRole!=null&&queryUserRole!=""){
        //    smbmsUser.setUserRole(Integer.valueOf(queryUserRole));
       // }
        IPage<SmbmsProvider> smbmsUserByPage= smbmsProviderService.getSmbmsProviderByPage(page,smbmsProvider);
        //准备数据 从数据库当中查找数据，并放到session 当中去
        //servlet ==>service ==> dao

        HttpSession session = req.getSession();
        session.setAttribute("providerList",smbmsUserByPage.getRecords());
        //总页数
        session.setAttribute("totalPageCount",smbmsUserByPage.getPages());

        //总条数
        session.setAttribute("totalCount",smbmsUserByPage.getTotal());
        //当前页
        session.setAttribute("currentPageNo",smbmsUserByPage.getCurrent());
        return "jsp/providerlist";
    }
}
